package com.xq.sboot.servlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * 功能说明: 手动注册Servlet的类.不加@WebServlet注解.
 * <p>创建时间:2018-12-14 10:18</p>
 *
 * @author <a href="https://gitee.com/gkq/microservice">郭凯强</a>
 * @since 1.0.0
 */
public class ManualServlet extends HttpServlet {
    private final Logger logger = LoggerFactory.getLogger(ManualServlet.class);
    private final Marker marker = MarkerFactory.getMarker("ManualServlet");

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        logger.debug(marker,"service方法执行,请求URI={}",req.getRequestURI());
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        logger.debug(marker, "初始化{}", ManualServlet.class.getName());
    }

    @Override
    public void destroy() {
        super.destroy();
        logger.debug(marker, "退出Servlet容器时销毁{},销毁时刻={}", ManualServlet.class.getName(), new Date());
    }
}
